package com.yyg.controller;

import com.alibaba.fastjson.JSON;
import com.yyg.entity.MainMenu;
import com.yyg.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
//控制台页面
@CrossOrigin("http://localhost:8081")
@RestController
public class MenuController {
    @Autowired
    private MenuService menuService;

    @RequestMapping("/menus")
    public String getAllMenus(){
        System.out.println("访问成功");
        HashMap<String,Object> data=new HashMap<>();
        List<MainMenu> menus=menuService.getMenus();
        if (menus!=null){
            data.put("menus",menus);
            data.put("flag",200);
        }else {
            data.put("flag",404);
        }
        System.out.println("data>>>>>"+data);
        String s = JSON.toJSONString(data);
        System.out.println("s>>>>>"+s);
        return s;
    }
}
